package com.github.freegeese.maven.plugin.autocode.configuration;

import com.github.freegeese.maven.plugin.autocode.metadata.Column;
import com.github.freegeese.maven.plugin.autocode.metadata.Table;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/4/12.
 */
public class ModelType {

    private String type;
    private Map columnMap = new LinkedHashMap();
    private Table table;

    public ModelType() {
        columnMap.put("sort", "sort");
        columnMap.put("parent", "parent");
        columnMap.put("path", "path");
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Map getColumnMap() {
        return columnMap;
    }

    public void setColumnMap(Map columnMap) {
        this.columnMap = columnMap;
    }

    public Table getTable() {
        return table;
    }

    public void setTable(Table table) {
        this.table = table;
    }

    public Column getColumn(String name) {
        Object columnName = columnMap.get(name);
        if (null == columnName) {
            return null;
        }
        List<Column> columns = getTable().getFilteredColumns();
        for (Column column : columns) {
            if (columnName.equals(column.getColumnName())) {
                return column;
            }
        }
        return null;
    }
}
